<?php
/**
 * Created by PhpStorm.
 * User: 1
 * Date: 2018/2/23
 * Time: 10:29
 */

namespace app\admin\model;


use think\Model;

class DownloadInfo extends Model
{
    /**
     * 查询所有用户信息
     * @author 吴铸峰 <1285443378@qq.com>
     * @return
     */
    public function getAll(){

        $order="";
        $keywords = trim(input('get.keywords'));
        if(!empty($keywords)){
            $where = ['nickname|remark' => ['like', "%{$keywords}%"]];
        }else{
            $where = [];
        }
        $data = $this
            ->alias('d')
            ->field('d.id,d.nickname,d.remark,d.openid,d.time,d.type,d.content,d.file_path')
            ->group('openid')
            ->where($where)
            ->order($order)
            ->select();
        if($data){
            foreach($data as $k => $v){
                $data[$k] = $v->toArray();
            }
        }

        return $data;
    }

    /**
     * 查询所有用户记录数
     * @author 巫玉梅 <1120504614@qq.com>
     * @return
     */
    public function getCount(){
        $order="";
        $keywords = trim(input('get.keywords'));
        if(!empty($keywords)){
            $where = ['nickname|remark' => ['like', "%{$keywords}%"]];
        }else{
            $where = [];
        }
        $count  =  $this
            ->alias('d')
            ->field('d.id,d.nickname,d.remark,d.openid,d.time,d.type,d.content,d.file_path')
            ->group('openid')
            ->where($where)
            ->order($order)
            ->count();
        return $count;
    }
    /**
     * 查询所有用户信息
     * @author 吴铸峰 <1285443378@qq.com>
     * @return
     */
    public function getAllDateById(){

        $order="";
        $keywords = trim(input('get.keywords'));
        if(!empty($keywords)){
            $where = ['nickname|remark' => "%{$keywords}%"];
        }else{
            $where = [];
        }
        $res = $this->where('id='.$_GET['id'])->find();
        $data = $this
            ->alias('d')
            ->field('d.id,d.nickname,d.remark,d.openid,d.date,d.time,d.type,d.content,d.file_path')
            ->where('openid',$res['openid'])
            ->group('date')
            ->where($where)
            ->order($order)
            ->select();
        if($data){
            foreach($data as $k => $v){
                $data[$k] = $v->toArray();
            }
        }

        return $data;
    }

    /**
     * 查询所有用户信息
     * @author 吴铸峰 <1285443378@qq.com>
     * @return
     */
    public function getAllById(){

        $order="";
        $keywords = trim(input('get.keywords'));
        if(!empty($keywords)){
            $where = ['nickname|remark' => "%{$keywords}%"];
        }else{
            $where = [];
        }
        $res = $this->where('id='.$_GET['id'])->find();
        $data = $this
            ->alias('d')
            ->field('d.id,d.nickname,d.remark,d.openid,d.date,d.time,d.type,d.content,d.file_path')
            ->where('openid',$res['openid'])
            ->where('date',$res['date'])
            ->where($where)
            ->order($order)
            ->select();
        if($data){
            foreach($data as $k => $v){
                $data[$k] = $v->toArray();
            }
        }

        return $data;
    }
}